<template>
  <div>
    <!-- <div class="toptitle">角色列表</div> -->
    <el-row id="order_total">
      <el-col :span="6">
        <div
          class="order_content"
          v-bind:class="upLowerClass"
          @click="toggleUpLowerStatus(3)"
        >
          <div class="order_total_title">上架商品数</div>
          <div class="order_total_info">
            <span class="order_data">{{ totalData.upLowerGoodsNum }}</span>
            <span class="order_dw"></span>
          </div>
        </div>
      </el-col>
      <el-col :span="6">
        <div
          class="order_content"
          v-bind:class="unUpLowerClass2"
          @click="toggleUpLowerStatus(2)"
        >
          <div class="order_total_title">下架商品数</div>
          <div class="order_total_info">
            <span class="order_data">{{ totalData.lowerNum }}</span>
            <span class="order_dw"></span>
          </div>
        </div>
      </el-col>
      <el-col :span="6">
        <div
          class="order_content"
          v-bind:class="unUpLowerClass"
          @click="toggleUpLowerStatus(1)"
        >
          <div class="order_total_title">未上架商品数</div>
          <div class="order_total_info">
            <span class="order_data">{{ totalData.unUpLowerGoodsNum }}</span>
            <span class="order_dw"></span>
          </div>
        </div>
      </el-col>
      <el-col :span="6">
        <div class="order_content" @click="toggleUpLowerStatus('')">
          <div class="order_total_title">商品总数</div>
          <div class="order_total_info">
            <span class="order_data">{{ totalData.goodsNum }}</span>
            <span class="order_dw"></span>
          </div>
        </div>
      </el-col>
    </el-row>
    <el-form
      :inline="true"
      :model="formInline"
      class="demo-form-inline"
      @keyup.enter.native="search()"
    >
      <!-- <el-row :span="24">
                <el-col :span="6"> -->
      <el-form-item label="商品名称">
        <br />
        <br />
        <el-input
          v-model="formInline.goodsName"
          clearable
          style="margin-left:-80px;width:200px"
        ></el-input>
      </el-form-item>
      <!-- </el-col>
                <el-col :span="6"> -->
      <el-form-item label="商品分类" style="margin-left:20px">
        <br />
        <br />
        <el-select
          v-model="formInline.goodsTypeId"
          clearable
          style="margin-left:-80px;width:200px"
        >
          <el-option
            v-for="(send, i) in typeData"
            :key="i"
            :value="send.goodsTypeId"
            :label="send.goodsTypeName"
          ></el-option>
        </el-select>
      </el-form-item>
      <!-- </el-col>
                <el-col :span="6"> -->
      <el-form-item label="上架状态" style="margin-left:20px">
        <br />
        <br />
        <el-select
          v-model="formInline.isShelf"
          clearable
          style="margin-left:-80px;width:200px"
        >
          <el-option
            v-for="(send, i) in isShelfList"
            :key="i"
            :value="send.isShelf"
            :label="send.isShelfName"
          ></el-option>
        </el-select>
      </el-form-item>
      <!-- </el-col>
                <el-col :span="6"> -->
      <el-form-item label="状态" style="margin-left:40px">
        <br />
        <br />
        <el-select
          v-model="formInline.status"
          style="margin-left:-80px;width:200px"
          clearable
        >
          <el-option label="总部禁用" :value="0"></el-option>
          <el-option label="总部启用" :value="1"></el-option>
        </el-select>
      </el-form-item>
      <!-- </el-col>
            </el-row>
            <el-row :span="24"> -->
      <el-form-item label="是否为限购商品">
        <br />
        <br />
        <el-select
          v-model="formInline.isBuyLimit"
          style="margin-left:-80px;width:200px"
          clearable
        >
          <el-option label="是" :value="1"></el-option>
          <el-option label="否" :value="0"></el-option>
        </el-select>
      </el-form-item>
      <br />
      <el-form-item label="商品类型">
        <br />
        <br />
        <el-select
          v-model="formInline.goodsStyle"
          clearable
          style="margin-left:-80px;width:200px"
        >
          <el-option label="普通商品" value="1"></el-option>
          <el-option label="宴席商品" value="2"></el-option>
          <el-option label="生日活动专属" value="3"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="是否有定时任务">
        <br />
        <br />
        <el-select
          v-model="formInline.isTiming"
          style="margin-left:-100px;width:200px"
          clearable
        >
          <el-option label="是" :value="1"></el-option>
          <el-option label="否" :value="0"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item style="margin-left:850px;text-align:right;">
        <el-button
          type="primary"
          @click="search()"
          size="mini"
          icon="el-icon-search"
          >查询</el-button
        >
        <!-- </el-form-item>
                <el-form-item> -->
        <el-button
          type="primary"
          @click="kong()"
          size="mini"
          icon="el-icon-delete"
          >清空</el-button
        >
        <!-- </el-form-item>
                <el-form-item> -->
        <!-- <el-button
          type="primary"
          @click="batchAddClick()"
          size="mini"
          icon="el-icon-plus"
          >批量上架</el-button
        > -->
        <!-- </el-form-item> -->
        <!-- <el-form-item> -->
        <!-- <el-button
          type="primary"
          @click="batchDelClick()"
          size="mini"
          icon="el-icon-minus"
          >批量下架</el-button
        > -->
      </el-form-item>
      <!-- </el-row> -->
    </el-form>
    <div class="limittabletwo">
      <el-table
        ref="multipleTable"
        tooltip-effect="dark"
        style="width: 100%;height:500px"
        height="400px"
        :row-class-name="tableRowClassName"
        v-loading="loading"
        @selection-change="handleSelectionChange"
        :data="tableData"
        border
        :header-cell-style="{ background: '#eef1f6', color: '#606266' }"
      >
        <el-table-column
          type="selection"
          width="60"
          :selectable="selectInit"
          align="center"
          disabled
        ></el-table-column>
        <!--<el-table-column type="index" label="序号" align="center" :index="indexMethod" width="60" fixed></el-table-column>-->
        <el-table-column
          prop="orgSeqName"
          label="大区"
          width="160"
          align="left"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="goodsName"
          label="商品名称"
          width="160"
          align="left"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="barCode"
          label="国际条码"
          width="160"
          align="right"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="goodsSeq"
          label="商品编码"
          width="160"
          align="left"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column
          prop="unitName"
          label="计量单位"
          align="center"
        ></el-table-column>
        <el-table-column
          prop="goodsTypeName"
          label="分类名称"
          width="160"
          align="center"
          show-overflow-tooltip
        ></el-table-column>
        <el-table-column align="center" prop="picture" label="图片">
          <template slot-scope="scope">
            <img
              :src="scope.row.picture.picUrl"
              v-if="scope.row.picture != '' && scope.row.picture != null"
              width="70"
              @click="$seeImage"
              height="50"
            />
          </template>
        </el-table-column>
        <el-table-column
          prop="createTime"
          label="创建时间"
          width="200"
          align="center"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.createTime != null">{{
              scope.row.createTime
            }}</span>
            <span v-if="scope.row.createTime == null">-</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="updateTime"
          label="上架时间"
          width="200"
          align="center"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.updateTime != null">{{
              scope.row.updateTime
            }}</span>
            <span v-if="scope.row.updateTime == null">——————————</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="timingOnShelfTime"
          label="定时任务"
          width="220"
          align="center"
        >
          <template slot-scope="scope">{{
            scope.row.timingOnShelfTime != null && scope.row.isTiming === 1
              ? scope.row.timingOnShelfTime.substring(0, 10) +
                '至' +
                scope.row.timingOffShelfTime.substring(0, 10)
              : '——————————'
          }}</template>
        </el-table-column>
        <el-table-column
          prop="isShelf"
          label="上架状态"
          width="120"
          align="center"
        >
          <template slot-scope="scope">
            <span v-if="scope.row.isShelf !== 2 && scope.row.isShelf !== 3"
              >未上架</span
            >
            <span v-if="scope.row.isShelf === 2">大区下架</span>
            <span v-if="scope.row.isShelf === 3">大区上架</span>
          </template>
        </el-table-column>
        <el-table-column
          prop="isBuyLimit"
          label="是否限购"
          width="120"
          align="center"
        >
          <template slot-scope="scope">{{
            scope.row.isBuyLimit === 1 ? '是' : '否'
          }}</template>
        </el-table-column>
        <el-table-column
          prop="goodsStyle"
          label="商品类型"
          width="120"
          align="center"
        >
          <template slot-scope="scope">{{
            scope.row.goodsStyle === 1
              ? '普通商品'
              : scope.row.goodsStyle === 2
              ? '宴席商品'
              : '生日活动专属'
          }}</template>
        </el-table-column>
        <el-table-column
          prop="isTiming"
          label="是否定时任务"
          width="120"
          align="center"
        >
          <template slot-scope="scope">{{
            scope.row.isTiming === 1 ? '是' : '否'
          }}</template>
        </el-table-column>
        <!-- <el-table-column prop="saleLowerPrice" label="总部底价（元）" align="right" :formatter=fixData></el-table-column> -->
        <el-table-column
          prop="salePrice"
          label="总部标准价（元）"
          align="right"
          :formatter="fixData"
        ></el-table-column>
        <!-- <el-table-column prop="saleUpperPrice" label="总部上限价（元）" align="right" :formatter=fixData></el-table-column> -->
        <!-- <el-table-column prop="warzooeLowerPrice" label="大区定价" align="center">
            <template slot-scope="scope">
              <el-input v-if="scope.row.isShelf != 2"
                v-model="scope.row.warzooeLowerPrice"
                type="text"
                style="text-align:right;text-align-last:right"
                @keyup.native='keyupEvent($event,scope.row.warzooeLowerPrice)'
                @change="updateWarGoodsPrice(scope.row)"
              ></el-input>
              <span v-if="scope.row.isShelf == 2">-</span>
            </template>
                </el-table-column>-->

        <el-table-column label="操作" width="90" align="center" fixed="right">
          <template slot-scope="scope">
            <el-button size="mini" @click="showDetail(scope.row)" type="text"
              >明细</el-button
            >
            <!-- <el-button
              size="small"
              v-if="scope.row.status != 0 && scope.row.isShelf != 3"
              @click="addClick(scope.row)"
              type="text"
              >上架</el-button
            >
            <el-button
              size="small"
              v-if="scope.row.isShelf == 3"
              @click="delClick(scope.row)"
              type="text"
              >下架</el-button
            > -->
            <el-button size="mini" @click="timingTask(scope.row)" type="text"
              >定时任务</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <el-form :inline="true" :model="formInline">
        <el-form-item style="margin-top: 0px;"></el-form-item>
      </el-form>
      <div class="block" style="margin-top:-22px">
        <el-pagination
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :page-sizes="[10, 20, 30, 50, 100, 150, 200]"
          :current-page="listQuery.current"
          :page-size="listQuery.size"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        ></el-pagination>
      </div>
    </div>
    <el-dialog title="定时任务" :visible.sync="dialogVisible" width="65%">
      <el-form
        :model="valueForm"
        :rules="rules"
        ref="valueForm"
        label-width="120px"
      >
        <span style="margin-left: 120px;">设置定时上下架时间</span>
        <el-form-item label prop style="margin-top: 10px;">
          <el-date-picker
            v-model="valueForm.value1"
            type="datetimerange"
            value-format="yyyy-MM-dd HH:mm:ss"
            align="right"
            start-placeholder="上架日期"
            end-placeholder="下架日期"
            :picker-options="pickerOptions"
            :default-time="['00:00:00', '23:59:59']"
          ></el-date-picker>
          <!-- <el-date-picker
                        v-model="valueForm.value1"
                        type="daterange"
                        value-format="yyyy-MM-dd"
                        range-separator="~"
                        start-placeholder="请选择上架日期"
                        end-placeholder="请选择下架日期"
                        :picker-options="pickerOptions"
                    ></el-date-picker>-->
          <p class="tips" style="margin-top: 10px;">
            *商品在设置好的定时上下架时间完成上下架任务
          </p>
          <div class="el-dialog-div">
            <el-timeline>
              <el-timeline-item
                v-for="(activity, index) in activities"
                :key="index"
                :timestamp="activity.createTime"
                >{{ activity.serviceDesc }}</el-timeline-item
              >
            </el-timeline>
          </div>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false" size="small">取 消</el-button>
        <el-button
          type="primary"
          @click="updateWarzoneGoods()"
          size="small"
          :disabled="isDisable"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {
  getProductTotalInfo,
  queryGoodsCategorys,
  batchRenewWarzoneGoods,
  batchDelWarzoneGoods,
  queryWarzoneGoodsList,
  getProductList,
  updateWarGoodsPrice,
  updateWarzoneGoods,
  queryOperationRecords,
} from '@/api/warProductmanage';
import qs from 'qs';
export default {
  data() {
    return {
      dialogVisible: false,
      loading: true,
      isDisable: false,
      logininfo: {},
      orgSeq: '',
      orgType: '2', //大区
      orgName: '',
      valueForm: {
        value1: [],
        goodsId: '',
        isTiming: '1',
        warzoneGoodsId: '',
        goodsName: '',
        isShelf: '',
      },
      pickerOptions: {
        // 限制时间
        // selectableRange: ['00:00:00 - 00:00:01','23:59:58 - 23:59:58'],
        disabledDate(time) {
          return time.getTime() < Date.now();
        },
      },
      rules: {},
      totalData: {
        goodsNum: 0,
        upLowerGoodsNum: 0,
        unUpLowerGoodsNum: 0,
        lowerNum: 0,
      },
      activities: [],
      typeData: [],
      isShelfList: [
        {
          isShelf: '3',
          isShelfName: '大区上架',
        },
        {
          isShelf: '2',
          isShelfName: '大区下架',
        },
        {
          isShelf: '1',
          isShelfName: '未上架',
        },
        // , {
        //   isShelf: "",
        //   isShelfName: '全部'
        // }
      ],
      formInline: {
        goodsName: '',
        goodsTypeId: '',
        isShelf: '',
        upLowerStatus: '',
        status: 1,
        isBuyLimit: '',
        isTiming: '',
        goodsStyle: '',
      },
      listQuery: {
        current: 1,
        size: 100,
      },
      total: 0,
      tableData: [],
      batchOpeGoods: [],
      batchSelGoods: [],
    };
  },
  created() {
    this.getProductType();
    this.getWarzoneInfo();
  },
  mounted() {
    this.getProductTotalInfo();
    this.queryWarzoneGoodsList();
  },
  methods: {
    //获取商品分类列表
    getProductType(v) {
      let data = {};
      queryGoodsCategorys(data).then((res) => {
        this.typeData = res.records;
      });
    },
    // 获取大区信息
    getWarzoneInfo() {
      this.logininfo = localStorage.getItem('logininfo');
      this.orgSeq = JSON.parse(this.logininfo).orgSeq;
      //this.orgType = JSON.parse(this.logininfo).orgType;
      //this.orgName = JSON.parse(this.logininfo).orgList[0].orgName;
    },
    //查询合计数据
    getProductTotalInfo() {
      let data = { orgSeq: this.orgSeq, orgType: this.orgType };
      getProductTotalInfo(data).then((res) => {
        this.totalData = {
          goodsNum: res.result.total,
          upLowerGoodsNum: res.result.upNum,
          unUpLowerGoodsNum: res.result.noUpNum,
          lowerNum: res.result.lowerNum,
        };
      });
    },
    //头部点击切换上下架状态
    toggleUpLowerStatus(status) {
      if (this.formInline.isShelf === status) {
        // this.formInline.upLowerStatus = "";
        this.formInline.isShelf = '';
      } else {
        // this.formInline.upLowerStatus = status;
        this.formInline.isShelf = String(status);
      }
      this.search();
    },
    //查询
    search() {
      this.listQuery.current = 1;
      this.queryWarzoneGoodsList();
    },
    //清空
    kong() {
      this.formInline.goodsName = '';
      this.formInline.goodsTypeId = '';
      this.formInline.isShelf = '';
      this.formInline.status = 1;
      this.formInline.isBuyLimit = '';
      this.formInline.isTiming = '';
      this.formInline.goodsStyle = '';
    },
    //定价保留两位小数
    keyupEvent(e, input) {
      e.target.value = e.target.value.replace(/[^\d.]/g, '');
      e.target.value = e.target.value.replace(/\.{2,}/g, '.');
      e.target.value = e.target.value.replace(/^\./g, '0.');
      e.target.value = e.target.value.replace(
        /^\d*\.\d*\./g,
        e.target.value.substring(0, e.target.value.length - 1)
      );
      e.target.value = e.target.value.replace(/^0[^\.]+/g, '0');
      e.target.value = e.target.value.replace(/^(\d+)\.(\d\d).*$/, '$1.$2');
      this.input = e.target.value;
    },
    //修改定价
    updateWarGoodsPrice(v) {
      if (isNaN(v.warzooeLowerPrice) || v.warzooeLowerPrice == '') {
        v.warzooeLowerPrice = v.saleLowerPrice;
      }
      if (v.warzooeLowerPrice < v.saleLowerPrice) {
        this.$message({
          showClose: true,
          message: '定价不能小于总部底价',
          type: 'warning',
        });
        return;
      }
      if (v.warzooeLowerPrice > v.saleUpperPrice) {
        this.$message({
          showClose: true,
          message: '定价不能高于总部上限价',
          type: 'warning',
        });
        return;
      }
      let itemUpLower = 1;
      if (v.isShelf != 1) {
        itemUpLower = 0;
      }
      let data = {
        orgSeq: this.orgSeq,
        warzooeLowerPrice: v.warzooeLowerPrice,
        warzonePriceId: v.warzonePriceId,
        goodsId: v.goodsId,
        upLower: itemUpLower, //传入当前商品是否必选 0否 1是
      };
      updateWarGoodsPrice(data).then((res) => {
        if (res.code == 1) {
          this.$message({
            showClose: true,
            message: res.message,
            type: 'success',
          });
        } else {
          this.$message({
            showClose: true,
            message: res.message,
            type: 'error',
          });
        }

        this.queryWarzoneGoodsList();
      });
    },
    //明细
    showDetail(v) {
      this.$router.push({
        name: 'productDetail',
        params: {
          edit: v,
        },
      });
    },
    //监听选择器
    handleSelectionChange(val) {
      this.batchSelGoods = val;
    },
    //批量上架
    batchAddClick() {
      if (this.batchSelGoods.length == 0) {
        this.$message({
          showClose: true,
          message: '请先挑选要批量上架的商品',
          type: 'info',
        });
        return false;
      }
      this.batchOpeGoods = [];
      for (let index = 0; index < this.batchSelGoods.length; index++) {
        let row = this.batchSelGoods[index];
        if (row.status != 0) {
          this.batchOpeGoods.push({
            orgSeq: this.orgSeq,
            goodsId: row.goodsId,
          });
        }
      }
      let data = this.batchOpeGoods;
      this.loading = true;
      batchRenewWarzoneGoods(data).then((res) => {
        this.$message({
          showClose: true,
          message: '上架大区商品成功',
          type: 'success',
        });
        this.loading = false;
        this.queryWarzoneGoodsList();
        this.getProductTotalInfo();
      });
    },
    //上架
    addClick(v) {
      this.batchOpeGoods = [];
      this.batchOpeGoods.push({ orgSeq: this.orgSeq, goodsId: v.goodsId });
      let data = this.batchOpeGoods;
      batchRenewWarzoneGoods(data).then((res) => {
        this.$message({
          showClose: true,
          message: '上架大区商品成功',
          type: 'success',
        });
        this.queryWarzoneGoodsList();
        this.getProductTotalInfo();
      });
    },
    //批量下架
    batchDelClick() {
      if (this.batchSelGoods.length == 0) {
        this.$message({
          showClose: true,
          message: '请先挑选要批量下架的商品',
          type: 'info',
        });
        return false;
      }
      this.batchOpeGoods = [];
      for (let index = 0; index < this.batchSelGoods.length; index++) {
        let row = this.batchSelGoods[index];
        this.batchOpeGoods.push({ orgSeq: this.orgSeq, goodsId: row.goodsId });
      }
      let data = this.batchOpeGoods;
      this.loading = true;
      batchDelWarzoneGoods(data).then((res) => {
        this.$message({
          showClose: true,
          message: '下架大区商品成功',
          type: 'success',
        });
        this.loading = false;
        this.queryWarzoneGoodsList();
        this.getProductTotalInfo();
      });
    },
    //下架
    delClick(v) {
      this.batchOpeGoods = [];
      this.batchOpeGoods.push({ orgSeq: this.orgSeq, goodsId: v.goodsId });
      let data = this.batchOpeGoods;
      batchDelWarzoneGoods(data).then((res) => {
        this.$message({
          showClose: true,
          message: '下架大区商品成功',
          type: 'success',
        });
        this.queryWarzoneGoodsList();
        this.getProductTotalInfo();
      });
    },
    //表格数据获取
    queryWarzoneGoodsList() {
      let data = {
        current: this.listQuery.current,
        size: this.listQuery.size,
        condition: {
          goodsName: this.formInline.goodsName,
          goodsTypeId: this.formInline.goodsTypeId,
          isShelf: this.formInline.isShelf,
          upLowerStatus: this.formInline.upLowerStatus,
          status: this.formInline.status,
          orgSeq: this.orgSeq,
          isBuyLimit: this.formInline.isBuyLimit,
          isTiming: this.formInline.isTiming,
          goodsStyle: this.formInline.goodsStyle,
        },
        ascs: [],
        descs: [],
      };
      queryWarzoneGoodsList(data).then((res) => {
        if (res != null && res.records != null) {
          res.records.forEach((item, i) => {
            item.warzooeLowerPrice = this.toPrice(item.warzooeLowerPrice);
          });
        }
        this.loading = false;
        this.tableData = res.records;
        this.total = res.total;
      });
    },
    queryOperationRecords(v) {
      let data = {
        current: 1,
        size: 999,
        condition: {
          targeId: v.warzoneGoodsId,
          orgSeq: this.orgSeq,
        },
        ascs: [],
        descs: [],
      };
      queryOperationRecords(data).then((res) => {
        this.activities = res.records;
      });
    },
    handleSizeChange(val) {
      this.listQuery.size = val;
      this.queryWarzoneGoodsList();
    },
    handleCurrentChange(val) {
      this.listQuery.current = val;
      this.queryWarzoneGoodsList();
    },
    indexMethod(index) {
      let curpage = this.listQuery.current; //单前页码，具体看组件取值
      let limitpage = this.listQuery.size; //每页条数，具体是组件取值
      return index + 1 + (curpage - 1) * limitpage;
    },
    fixData(row, column, cellValue, index) {
      if (cellValue != null && !isNaN(cellValue)) {
        return cellValue.toFixed(2);
      } else {
        return cellValue;
      }
    },
    toPrice(val, type) {
      // 值，符号
      if (val === null || val === undefined || val === '') {
        return '0.00';
      } else {
        var data = Number(val)
          .toFixed(2)
          .split('.');
        var data2 = data[0]
          .split('')
          .reverse()
          .join('');
        var newData = data2;
        if (type) {
          return (
            type +
            newData
              .split('')
              .reverse()
              .join('')
              .slice(1) +
            '.' +
            data[1]
          );
        } else {
          return (
            newData
              .split('')
              .reverse()
              .join('')
              .slice(0) +
            '.' +
            data[1]
          );
        }
      }
    },
    selectInit(row, index) {
      if (row.status == 0) {
        return false; //不可勾选
      } else {
        return true; //可勾选
      }
    },
    tableRowClassName({ row, rowIndex }) {
      if (row != undefined) {
        if (row.status == 3) {
          return 'warning-row';
        } else if (row.status == 0) {
          return 'success-row';
        }
      }
      return '';
    },
    timingTask(v) {
      this.dialogVisible = true;
      this.valueForm.warzoneGoodsId = v.warzoneGoodsId;
      if (v.isTiming == 1) {
        this.valueForm.value1 = [v.timingOnShelfTime, v.timingOffShelfTime];
      } else {
        this.valueForm.value1 = [];
      }
      this.valueForm.isTiming = v.isTiming;
      this.valueForm.isShelf = v.isShelf;
      this.valueForm.goodsName = v.goodsName;
      this.valueForm.goodsId = v.goodsId;
      this.queryOperationRecords(v);
    },
    //修改定时任务
    updateWarzoneGoods() {
      if (this.valueForm.isTiming == 1) {
        this.$message.info('定时任务已存在,请失效后再设置');
        this.dialogVisible = false;
        return;
      }
      if (this.valueForm.isShelf == 3) {
        this.$message.info('该商品大区已上架,请下架后再设置定时任务');
        this.dialogVisible = false;
        return;
      }
      if (this.valueForm.value1[0] == '' || this.valueForm.value1[0] == null) {
        this.$message.error('请输入上架时间');
        return;
      }
      if (this.valueForm.value1[1] == '' || this.valueForm.value1[1] == null) {
        this.$message.error('请输入下架结束时间');
        return;
      }
      if (this.valueForm.value1[1] < this.valueForm.value1[0]) {
        this.$message({
          showClose: true,
          message: '上下架时间范围不合理',
          type: 'warning',
        });
        return;
      }

      this.isDisable = true;
      setTimeout(() => {
        this.isDisable = false;
      }, 2000);

      let data = {
        orgSeq: this.orgSeq,
        goodsName: this.valueForm.goodsName,
        goodsId: this.valueForm.goodsId,
        timingOnShelfTime: this.valueForm.value1[0],
        timingOffShelfTime: this.valueForm.value1[1],
        warzoneGoodsId: this.valueForm.warzoneGoodsId,
        isTiming: this.valueForm.isTiming, //传入当前商品是否必选 0否 1是
      };
      // console.log(data);
      updateWarzoneGoods(data).then((res) => {
        if (res.code == 1) {
          this.$message({
            showClose: true,
            message: '定时任务设置成功',
            type: 'success',
          });
          this.dialogVisible = false;
        } else {
          this.$message({
            showClose: true,
            message: '定时任务设置失败',
            type: 'error',
          });
          this.dialogVisible = false;
        }

        this.queryWarzoneGoodsList();
      });
    },
  },
  //其他
  computed: {
    LowerClass: function() {
      return {
        base: true,
        'bg-sel': this.formInline.isShelf == '',
      };
    },
    upLowerClass: function() {
      return {
        base: true,
        'bg-sel': this.formInline.isShelf == '3',
      };
    },
    unUpLowerClass: function() {
      return {
        base: true,
        'bg-sel': this.formInline.isShelf == '1',
      };
    },
    unUpLowerClass2: function() {
      return {
        base: true,
        'bg-sel': this.formInline.isShelf == '2',
      };
    },
  },
};
</script>
<style lang="less" scoped>
.el-row {
  margin-bottom: 20px;
  &:last-child {
    margin-bottom: 0;
  }
}
.el-col {
  border-radius: 4px;
}
.order_content {
  cursor: pointer;
  width: 250px;
  padding: 20px 0;
  margin: 0 auto;
  text-align: center;
  overflow: hidden;
  border-radius: 4px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.12), 0 0 6px rgba(0, 0, 0, 0.04);
}
.order_content .order_total_title {
  color: #000;
}
.order_content .order_total_info {
  margin: 10px 0;
}
.order_content .order_data {
  font-size: 1.4em;
  font-weight: bold;
}
.order_content .compared_title {
  font-size: 0.8em;
  color: #999;
}
.bg-sel {
  background: #fafad2;
}
.el-input__inner {
  padding: 0 5px;
}
.demo-form-inline .el-form-item {
  margin-bottom: 0px;
}
.el-table .warning-row {
  background: oldlace;
}
.el-table .success-row {
  background: #f0f9eb;
}
.tips {
  margin-left: 10px;
  color: red;
  font-size: 12px;
}
.el-dialog-div {
  height: 18vh;
  overflow: auto;
}
.el-date-range-picker__editor el-input el-input--small .el-input__inner {
  disabled: disabled !important;
}
</style>
